/**
 * Copyright 2025 Adobe. All rights reserved.
 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy
 * of the License at http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
 * OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */

@media (forced-colors: active) {
    :host {
        --highcontrast-stepper-border-color: CanvasText;
        --highcontrast-stepper-border-color-hover: Highlight;
        --highcontrast-stepper-border-color-focus: Highlight;
        --highcontrast-stepper-border-color-focus-hover: Highlight;
        --highcontrast-stepper-border-color-keyboard-focus: CanvasText;
        --highcontrast-stepper-focus-indicator-color: Highlight;
    }

    :host([invalid]) #textfield {
        --highcontrast-stepper-border-color: Highlight;
        --highcontrast-stepper-border-color-hover: Highlight;
        --highcontrast-stepper-border-color-focus: Highlight;
        --highcontrast-stepper-border-color-focus-hover: Highlight;
        --highcontrast-stepper-border-color-keyboard-focus: Highlight;
    }

    :host([disabled]) #textfield {
        --highcontrast-stepper-border-color: GrayText;
        --highcontrast-stepper-buttons-border-width: var(--mod-stepper-border-width, var(--spectrum-stepper-border-width));
    }

    :host([focused]:not([disabled])) #textfield,
    :host(:not([disabled])) #textfield:focus {
        --highcontrast-stepper-border-color: var(--highcontrast-stepper-border-color-focus);
    }

    @media (hover: hover) {
        :host(:not([disabled]):hover) #textfield {
            --highcontrast-stepper-border-color: var(--highcontrast-stepper-border-color-hover);
        }

        :host([focused]:not([disabled]):hover) #textfield,
        :host(:not([disabled]):hover) #textfield:focus {
            --highcontrast-stepper-border-color: var(--highcontrast-stepper-border-color-focus-hover);
        }
    }

    :host([keyboard-focused]:not([disabled])) #textfield,
    :host(:not([disabled])) #textfield:focus-visible {
        --highcontrast-stepper-border-color: var(--highcontrast-stepper-border-color-keyboard-focus);
    }

    .input {
        --highcontrast-textfield-border-color: var(--highcontrast-stepper-border-color);
    }

    .button {
        --highcontrast-infield-button-border-color: var(--highcontrast-stepper-border-color);
        --highcontrast-infield-button-border-color-active: var(--highcontrast-stepper-border-color);
    }
}

:host {
    --spectrum-stepper-border-color: var(--highcontrast-stepper-border-color, var(--mod-stepper-border-color, var(--spectrum-stepper-border-color-default)));
    --spectrum-stepper-border-radius: var(--mod-stepper-border-radius, var(--spectrum-corner-radius-100));
    --spectrum-stepper-focus-indicator-width: var(--mod-stepper-focus-indicator-width, var(--spectrum-focus-indicator-thickness));
    --spectrum-stepper-focus-indicator-gap: var(--mod-stepper-focus-indicator-gap, var(--spectrum-focus-indicator-gap));
    --spectrum-stepper-focus-indicator-color: var(--highcontrast-stepper-focus-indicator-color, var(--mod-stepper-focus-indicator-color, var(--spectrum-focus-indicator-color)));
    --spectrum-stepper-animation-duration: var(--mod-stepper-animation-duration, var(--spectrum-animation-duration-100));
}

#textfield,
:host([size="m"]) #textfield {
    --spectrum-stepper-button-width: var(--mod-stepper-button-width, var(--spectrum-in-field-button-width-stacked-medium));
    --spectrum-stepper-height: var(--mod-stepper-height, var(--spectrum-component-height-100));
}

:host([size="s"]) #textfield {
    --spectrum-stepper-button-width: var(--mod-stepper-button-width, var(--spectrum-in-field-button-width-stacked-small));
    --spectrum-stepper-height: var(--mod-stepper-height, var(--spectrum-component-height-75));
}

:host([size="l"]) #textfield {
    --spectrum-stepper-button-width: var(--mod-stepper-button-width, var(--spectrum-in-field-button-width-stacked-large));
    --spectrum-stepper-height: var(--mod-stepper-height, var(--spectrum-component-height-200));
}

:host([size="xl"]) #textfield {
    --spectrum-stepper-button-width: var(--mod-stepper-button-width, var(--spectrum-in-field-button-width-stacked-extra-large));
    --spectrum-stepper-height: var(--mod-stepper-height, var(--spectrum-component-height-300));
}

:host([disabled]) #textfield {
    --spectrum-stepper-buttons-border-width: var(--spectrum-stepper-button-border-width-disabled);
    --spectrum-stepper-buttons-background-color: var(--spectrum-stepper-buttons-background-color-disabled);
}

:host([invalid]) #textfield {
    --mod-stepper-border-color: var(--mod-stepper-border-color-invalid, var(--spectrum-negative-border-color-default));
    --mod-stepper-border-color-hover: var(--mod-stepper-border-color-hover-invalid, var(--spectrum-negative-border-color-hover));
    --mod-stepper-border-color-focus: var(--mod-stepper-border-color-focus-invalid, var(--spectrum-negative-border-color-focus));
    --mod-stepper-border-color-focus-hover: var(--mod-stepper-border-color-focus-hover-invalid, var(--spectrum-negative-border-color-focus-hover));
    --mod-stepper-border-color-keyboard-focus: var(--mod-stepper-border-color-keyboard-focus-invalid, var(--spectrum-negative-border-color-key-focus));
}

:host([focused]:not([disabled])) #textfield,
:host(:not([disabled])) #textfield:focus {
    --mod-stepper-border-color: var(--highcontrast-stepper-border-color-focus, var(--mod-stepper-border-color-focus, var(--spectrum-stepper-border-color-focus)));
    --mod-stepper-buttons-border-color: var(--highcontrast-stepper-border-color-focus, var(--mod-stepper-border-color-focus, var(--spectrum-stepper-border-color-focus)));
}

:host([keyboard-focused]:not([disabled])) #textfield {
    --mod-stepper-border-color: var(--highcontrast-stepper-border-color-focus, var(--mod-stepper-border-color-focus, var(--spectrum-stepper-border-color-keyboard-focus)));
}

:host([quiet]) #textfield {
    --mod-stepper-buttons-background-color: transparent;
}

:host([quiet][keyboard-focused]:not([disabled])) #textfield {
    --mod-stepper-focus-indicator-visibility: visible;
}

:host([quiet][invalid]) #textfield {
    --mod-stepper-border-color: var(--mod-stepper-border-color-invalid, var(--spectrum-negative-border-color-default));
}

:host {
    --mod-infield-button-border-color: var(--mod-stepper-buttons-border-color, var(--spectrum-stepper-buttons-border-color));
    --mod-infield-button-border-color-quiet-disabled: var(--spectrum-disabled-border-color);
    --mod-infield-button-border-width: var(--mod-stepper-button-border-width, var(--spectrum-stepper-button-border-width));
    --mod-textfield-border-width: var(--mod-stepper-border-width, var(--spectrum-stepper-border-width));
    --mod-textfield-border-color: var(--spectrum-stepper-border-color);
}

#textfield:not(.spectrum-Stepper--quiet) {
    --mod-textfield-border-color-disabled: var(--spectrum-stepper-border-color-disabled);
}

:host(:not([disabled])[focused]) #textfield,
:host(:not([disabled])) #textfield:focus {
    --mod-infield-button-border-color: var(--highcontrast-stepper-border-color-focus, var(--mod-stepper-buttons-border-color-focus, var(--spectrum-stepper-buttons-border-color-focus)));
    --mod-textfield-focus-indicator-width: 0;
}

:host([keyboard-focused]:not([disabled])) #textfield,
:host(:not([disabled])) #textfield:focus-visible {
    --mod-infield-button-border-color: var(--highcontrast-stepper-border-color-keyboard-focus, var(--mod-stepper-buttons-border-color-keyboard-focus, var(--spectrum-stepper-buttons-border-color-keyboard-focus)));
    --mod-textfield-focus-indicator-width: 0;
    --mod-textfield-border-color: var(--highcontrast-stepper-border-color-keyboard-focus, var(--mod-stepper-border-color-keyboard-focus, var(--spectrum-stepper-border-color-keyboard-focus)));
    outline: var(--spectrum-stepper-focus-indicator-width) solid;
    outline-color: var(--spectrum-stepper-focus-indicator-color);
    outline-offset: var(--spectrum-stepper-focus-indicator-gap);
}

:host([invalid]) #textfield {
    --mod-infield-button-border-color: var(--highcontrast-stepper-border-color, var(--mod-stepper-border-color-invalid, var(--spectrum-stepper-border-color-invalid)));
    --mod-textfield-icon-spacing-inline-start-invalid: 0;
}

:host([invalid][focused]) #textfield,
:host([invalid]) #textfield:focus {
    --mod-infield-button-border-color: var(--highcontrast-stepper-border-color, var(--mod-stepper-border-color-focus-invalid, var(--spectrum-stepper-border-color-focus-invalid)));
}

:host([invalid][keyboard-focused]) #textfield,
:host([invalid]) #textfield:focus-visible {
    --mod-infield-button-border-color: var(--highcontrast-stepper-border-color, var(--mod-stepper-border-color-keyboard-focus-invalid, var(--spectrum-stepper-border-color-keyboard-focus-invalid)));
}

:host([quiet]) #textfield {
    --mod-infield-button-width-stacked: var(--mod-stepper-button-width-quiet, var(--spectrum-stepper-button-width));
    --mod-infield-button-border-color: var(--spectrum-stepper-border-color);
    --mod-infield-button-border-color-quiet: var(--spectrum-stepper-border-color);
    --mod-infield-button-border-block-end-width: var(--mod-stepper-border-width, var(--spectrum-stepper-border-width));
    --mod-infield-button-stacked-bottom-border-block-end-width: var(--mod-stepper-border-width, var(--spectrum-stepper-border-width));
    --mod-infield-button-stacked-bottom-border-radius-end-end: 0;
    --mod-infield-button-stacked-bottom-border-radius-end-start: 0;
    --mod-infield-button-fill-justify-content: flex-end;
    --mod-infield-button-inner-edge-to-fill: var(--spectrum-stepper-button-edge-to-fill);
    --mod-infield-button-edge-to-fill: var(--spectrum-stepper-button-edge-to-fill);
    --mod-textfield-focus-indicator-color: transparent;
    --mod-textfield-background-color: transparent;
    --mod-textfield-border-color-hover: var(--highcontrast-stepper-border-color, var(--mod-stepper-border-color-hover, var(--spectrum-stepper-border-color-hover)));
}

:host([quiet][focused]:not([disabled])) #textfield,
:host([quiet]:not([disabled])) #textfield:focus {
    --mod-infield-button-border-color: var(--highcontrast-stepper-border-color, var(--mod-stepper-border-color-focus, var(--spectrum-stepper-border-color-focus)));
}

:host([quiet][keyboard-focused]:not([disabled])) #textfield {
    --mod-infield-button-border-color: var(--highcontrast-stepper-border-color, var(--mod-stepper-border-color-keyboard-focus, var(--spectrum-stepper-border-color-keyboard-focus)));
}

@media (hover: hover) {
    :host(:not([disabled]):hover) #textfield {
        --mod-stepper-border-color: var(--highcontrast-stepper-border-color-hover, var(--mod-stepper-border-color-hover, var(--spectrum-stepper-border-color-hover)));
    }

    :host([focused]:not([disabled]):hover) #textfield,
    :host(:not([disabled]):hover) #textfield:focus {
        --mod-stepper-border-color: var(--highcontrast-stepper-border-color-focus-hover, var(--mod-stepper-border-color-focus-hover, var(--spectrum-stepper-border-color-focus-hover)));
        --mod-stepper-buttons-border-color: var(--highcontrast-stepper-border-color-focus-hover, var(--mod-stepper-border-color-focus-hover, var(--spectrum-stepper-border-color-focus-hover)));
    }

    :host([quiet]:not([disabled]):hover) #textfield {
        --mod-stepper-buttons-background-color: transparent;
    }

    :host(:hover) #textfield:not(.is-invalid, .is-disabled, .is-focused) {
        --mod-infield-button-border-color: var(--mod-stepper-buttons-border-color-hover, var(--spectrum-stepper-buttons-border-color-hover));
    }

    :host(:not([disabled])[focused]:hover) #textfield,
    :host(:not([disabled]):hover) #textfield:focus {
        --mod-infield-button-border-color: var(--mod-stepper-buttons-border-color-focus-hover, var(--spectrum-stepper-buttons-border-color-focus-hover));
        --mod-textfield-focus-indicator-width: 0;
        --mod-textfield-border-color: var(--highcontrast-stepper-border-color-focus-hover, var(--mod-stepper-border-color-focus-hover, var(--spectrum-stepper-border-color-focus-hover)));
    }

    :host([invalid]:hover) #textfield {
        --mod-infield-button-border-color: var(--highcontrast-stepper-border-color, var(--mod-stepper-border-color-hover-invalid, var(--spectrum-negative-border-color-hover)));
    }

    :host([invalid][focused]:hover) #textfield,
    :host([invalid]:hover) #textfield:focus {
        --mod-infield-button-border-color: var(--highcontrast-stepper-border-color, var(--mod-stepper-border-color-focus-hover-invalid, var(--spectrum-stepper-border-color-focus-hover-invalid)));
    }

    :host([quiet]:not([disabled]):hover) #textfield {
        --mod-textfield-border-color-hover: var(--highcontrast-stepper-border-color, var(--mod-stepper-border-color-hover, var(--spectrum-stepper-border-color-hover)));
        --mod-infield-button-border-color: var(--highcontrast-stepper-border-color, var(--mod-stepper-border-color-hover, var(--spectrum-stepper-border-color-hover)));
    }

    :host([quiet][focused]:not([disabled]):hover) #textfield,
    :host([quiet]:not([disabled]):hover) #textfield:focus {
        --mod-infield-button-border-color: var(--highcontrast-stepper-border-color, var(--mod-stepper-border-color-focus-hover, var(--spectrum-stepper-border-color-focus-hover)));
    }

    :host([quiet][keyboard-focused]:not([disabled]):hover) #textfield {
        --mod-infield-button-border-color: var(--highcontrast-stepper-border-color, var(--mod-stepper-border-color-hover, var(--spectrum-stepper-border-color-hover)));
    }
}

#textfield {
    --spectrum-stepper-width: var(--mod-stepper-width, calc(var(--spectrum-stepper-height) * var(--mod-stepper-min-width-multiplier, var(--spectrum-text-field-minimum-width-multiplier)) + var(--spectrum-stepper-button-width) + var(--mod-stepper-border-width, var(--spectrum-stepper-border-width)) * 2));
    inline-size: var(--spectrum-stepper-width);
    block-size: var(--spectrum-stepper-height);
    border-radius: var(--spectrum-stepper-border-radius);
    flex-flow: row;
    display: inline-flex;
    position: relative;
}

#textfield:before {
    content: "";
}

.input {
    border-inline-end-width: 0;
    border-start-end-radius: 0;
    border-end-end-radius: 0;
}

.buttons {
    box-sizing: border-box;
    block-size: var(--spectrum-stepper-height);
    inline-size: var(--spectrum-stepper-button-width);
    border-color: var(--spectrum-stepper-border-color);
    border-style: var(--mod-stepper-buttons-border-style, var(--spectrum-stepper-buttons-border-style));
    border-width: var(--highcontrast-stepper-buttons-border-width, var(--mod-stepper-buttons-border-width, var(--spectrum-stepper-buttons-border-width)));
    background-color: var(--mod-stepper-buttons-background-color, var(--spectrum-stepper-buttons-background-color));
    transition: border-color var(--spectrum-stepper-animation-duration) ease-in-out;
    border-inline-start-width: 0;
    flex-direction: column;
    justify-content: center;
    display: flex;
}

.buttons,
#textfield.hide-stepper .input {
    border-start-end-radius: var(--spectrum-stepper-border-radius);
    border-end-end-radius: var(--spectrum-stepper-border-radius);
}

#textfield.hide-stepper .input {
    border-inline-end-width: var(--mod-stepper-border-width, var(--spectrum-stepper-border-width));
}

:host([quiet]) #textfield {
    border-start-start-radius: 0;
    border-start-end-radius: 0;
    border-end-end-radius: 0;
    border-end-start-radius: 0;
}

:host([quiet]) .hide-stepper .input {
    border-inline-end-width: 0;
    border-end-end-radius: 0;
}

:host([quiet]):after {
    visibility: hidden;
    visibility: var(--mod-stepper-focus-indicator-visibility, hidden);
    content: "";
    inline-size: 100%;
    block-size: var(--spectrum-stepper-focus-indicator-width);
    background-color: var(--spectrum-stepper-focus-indicator-color);
    position: absolute;
    inset-block-end: calc((var(--spectrum-stepper-focus-indicator-gap) + var(--spectrum-stepper-focus-indicator-width)) * -1);
    inset-inline-start: 0;
}

:host([quiet][keyboard-focused]:not([disabled])) {
    outline: none;
}
